<template>
  <div class="index-container">
    <van-grid :gutter="15" :border="false" :column-num="2">
      <van-grid-item v-for="(item, index) in list" :key="index">
        <van-image width="100%" height="105" :src="item.cover" />
        <div class="content">
          <h3 class="title">{{ item.name }}</h3>
          <div class="jiage">
            抢购价:
            <span>
              <i>¥</i>
              <i style="font-size: 18px">{{ item.price }}</i>
            </span>
          </div>
          <div class="xuexi">{{ item.init_sale_num }}人已学习</div>
        </div>
      </van-grid-item>
    </van-grid>
    <div class="none" v-if="list.length < 1">
      <img :src="require('@/assets/images/quesheng-kong.png')" alt />
      <div>暂无收藏</div>
    </div>
  </div>
</template>

<script>
import { favLists } from '@/api/mine/collect'
export default {
  data() {
    return {
      queryParams: {
        type: 'pack'
      },
      list: []
    }
  },

  computed: {
    share_token() {
      return this.$store.getters.share_token
    }
  },

  mounted() {
    this.fetchList()
  },

  methods: {
    // 获取个人信息
    fetchList() {
      favLists(this.queryParams).then(res => {
        const data = res.data
        data.map(b => {
          b.is_status = true
        })
        this.list = data
      })
    },
    statusClick(row, index) {
      this.$set(this.list[index], 'is_status', !row.is_status)
    },
    // 金牌课详情
    toPackDetails(row) {
      const data = {
        id: row.id,
        token: this.share_token
      }
      this.$router.push({ path: '/pack-details', query: data })
    },
    // 阶段课详情
    toStageClass(row, goods) {
      const data = {
        goods_id: goods.id,
        stage_id: row.stage_id,
        is_buy: goods.is_buy
      }
      this.$router.push({ path: '/stage-class', query: data })
    }
  }
}
</script>

<style lang="scss" scoped>
.index-container {
  ::v-deep .van-grid {
    margin-top: 20px;
    .van-grid-item {
      box-shadow: 0px 1.5px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
    }
    .van-grid-item__content {
      box-shadow: 0px 1px 4px 0px rgba(210, 212, 213, 0.2);
      border-radius: 5px;
      padding: 0;
      overflow: hidden;
    }
    .content {
      box-sizing: border-box;
      width: 100%;
      padding: 8px 10px 10px;
      .title {
        font-size: 14px;
        font-weight: 600;
        color: #333333;
        line-height: 21px;
        @include textoverflow(1);
      }
      .jiage {
        font-size: 12px;
        color: #009697;
        line-height: 30px;
      }
      .xuexi {
        display: table;
        // margin-top: 10px;
        min-width: 75px;
        padding: 0 5px;
        height: 20px;
        line-height: 20px;
        font-size: 12px;
        color: #11a8a4;
        background: rgba(7, 120, 121, 0.1);
        border-radius: 2px;
      }
      .van-button {
        width: 27px;
        height: 14px;
        background: #fd953f;
        padding: 0;
        vertical-align: bottom;
        .van-button__text {
          font-size: 14px;
          font-weight: bold;
          color: #fffefe;
        }
      }
      .open_price {
        font-size: 9px;
        font-weight: 800;
        color: #009697;
        // line-height: 30px;
      }
      .open_number {
        margin-left: 4px;
        line-height: 14px;
        font-size: 6px;
        font-weight: 500;
        text-decoration: line-through;
        color: #999999;
      }
    }
  }
}
</style>
